package mhwi.helper;

import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import mhwi.powers.BaiRenPower;
import mhwi.powers.HongRenPower;
import mhwi.powers.HuangRenPower;

import java.util.ArrayList;

import static mhwi.constants.ModInfoConstant.MOD_ID;

public class ModHelper {
    public static String makeId(String name) {
        return MOD_ID + ":" + name;
    }

    public static String makePath(String root, String... paths) {
        StringBuilder finalPath = new StringBuilder(root);
        for (String path : paths) {
            finalPath.append("/").append(path);
        }
        return finalPath.toString();
    }

    public static String makeSimpleFileName(String... namesAndExtensions) {
        StringBuilder fileName = new StringBuilder();
        for (String nameAndExtension : namesAndExtensions) {
            fileName.append(nameAndExtension);
        }
        return fileName.toString();
    }

    public static String makeFileName(String root, String... namesAndExtension) {
        return makePath(root, makeSimpleFileName(namesAndExtension));
    }

    public static boolean hasRelic(String targetRelicId) {
        for (AbstractRelic relic : AbstractDungeon.player.relics) {
            if (relic.relicId.equals(targetRelicId)) {
                return true;
            }
        }
        return false;
    }

    public static boolean hasPowers(String... targetPowerId) {
        for (String powerId : targetPowerId) {
            if (!AbstractDungeon.player.hasPower(powerId)) {
                return false;
            }
        }
        return true;
    }

    public static int getPowersAmount(AbstractCreature creature, String powerId) {
        for (AbstractPower power : creature.powers) {
            if (power.ID.equals(powerId)) {
                return power.amount;
            }
        }
        return 0;
    }

    public static ArrayList<Integer> getPowersAmount(AbstractCreature creature, String... powerIds) {
        ArrayList<Integer> ret =  new ArrayList<>();
        for (String powerId : powerIds) {
            for (AbstractPower power : creature.powers) {
                if (power.ID.equals(powerId)) {
                    ret.add(power.amount);
                }
            }
        }
        return ret;
    }

    public static boolean hasQiRenPowers() {
        return ModHelper.hasPowers(BaiRenPower.POWER_ID) ||
                ModHelper.hasPowers(HuangRenPower.POWER_ID) ||
                ModHelper.hasPowers(HongRenPower.POWER_ID);
    }

    public static boolean isEnemyAttacking(AbstractMonster enemy) {
        switch (enemy.intent) {
            case ATTACK:
            case ATTACK_BUFF:
            case ATTACK_DEBUFF:
            case ATTACK_DEFEND:
                return true;
            default:
                return false;
        }
    }
}
